using System;
using System.Text;
namespace ServiceStack.Messaging
{
	public static class QueueNames<T>
	{
		public static string Priority
		{
			get;
			private set;
		}
		public static byte[] PriorityBytes
		{
			get;
			private set;
		}
		public static string In
		{
			get;
			private set;
		}
		public static byte[] InBytes
		{
			get;
			private set;
		}
		public static string Out
		{
			get;
			private set;
		}
		public static byte[] OutBytes
		{
			get;
			private set;
		}
		public static string Dlq
		{
			get;
			private set;
		}
		public static byte[] DlqBytes
		{
			get;
			private set;
		}
		public static string[] AllQueueNames
		{
			get
			{
				return new string[]
				{
					QueueNames<T>.In,
					QueueNames<T>.Priority,
					QueueNames<T>.Out,
					QueueNames<T>.Dlq
				};
			}
		}
		static QueueNames()
		{
			UTF8Encoding arg_29_0 = new UTF8Encoding(false);
			QueueNames<T>.Priority = QueueNames.ResolveQueueNameFn.Invoke(typeof(T).get_Name(), ".priorityq");
			QueueNames<T>.PriorityBytes = arg_29_0.GetBytes(QueueNames<T>.Priority);
			QueueNames<T>.In = QueueNames.ResolveQueueNameFn.Invoke(typeof(T).get_Name(), ".inq");
			QueueNames<T>.InBytes = arg_29_0.GetBytes(QueueNames<T>.In);
			QueueNames<T>.Out = QueueNames.ResolveQueueNameFn.Invoke(typeof(T).get_Name(), ".outq");
			QueueNames<T>.OutBytes = arg_29_0.GetBytes(QueueNames<T>.Out);
			QueueNames<T>.Dlq = QueueNames.ResolveQueueNameFn.Invoke(typeof(T).get_Name(), ".dlq");
			QueueNames<T>.DlqBytes = arg_29_0.GetBytes(QueueNames<T>.Dlq);
		}
	}
	public class QueueNames
	{
		public static string Exchange = "mx.servicestack";
		public static string ExchangeDlq = "mx.servicestack.dlq";
		public static string ExchangeTopic = "mx.servicestack.topic";
		public static string MqPrefix = "mq:";
		public static string QueuePrefix = "";
		public static string TempMqPrefix = QueueNames.MqPrefix + "tmp:";
		public static string TopicIn = QueueNames.MqPrefix + "topic:in";
		public static string TopicOut = QueueNames.MqPrefix + "topic:out";
		public static Func<string, string, string> ResolveQueueNameFn = new Func<string, string, string>(QueueNames.ResolveQueueName);
		private readonly Type messageType;
		public string Priority
		{
			get
			{
				return QueueNames.ResolveQueueNameFn.Invoke(this.messageType.get_Name(), ".priorityq");
			}
		}
		public string In
		{
			get
			{
				return QueueNames.ResolveQueueNameFn.Invoke(this.messageType.get_Name(), ".inq");
			}
		}
		public string Out
		{
			get
			{
				return QueueNames.ResolveQueueNameFn.Invoke(this.messageType.get_Name(), ".outq");
			}
		}
		public string Dlq
		{
			get
			{
				return QueueNames.ResolveQueueNameFn.Invoke(this.messageType.get_Name(), ".dlq");
			}
		}
		public static string ResolveQueueName(string typeName, string queueSuffix)
		{
			return QueueNames.QueuePrefix + QueueNames.MqPrefix + typeName + queueSuffix;
		}
		public static bool IsTempQueue(string queueName)
		{
			return queueName != null && queueName.StartsWith(QueueNames.TempMqPrefix, 5);
		}
		public static void SetQueuePrefix(string prefix)
		{
			QueueNames.TopicIn = prefix + QueueNames.MqPrefix + "topic:in";
			QueueNames.TopicOut = prefix + QueueNames.MqPrefix + "topic:out";
			QueueNames.QueuePrefix = prefix;
			QueueNames.TempMqPrefix = prefix + QueueNames.MqPrefix + "tmp:";
		}
		public QueueNames(Type messageType)
		{
			this.messageType = messageType;
		}
		public static string GetTempQueueName()
		{
			return QueueNames.TempMqPrefix + Guid.NewGuid().ToString("n");
		}
	}
}
